package com.cloudcc.mobile.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.BullGzlxAdapter;
import com.cloudcc.mobile.adapter.BullJxsAdapter;
import com.cloudcc.mobile.adapter.BullMendAdapter;
import com.cloudcc.mobile.entity.BullGzlxEntity;
import com.cloudcc.mobile.entity.BullJxsNewJob;

import java.util.List;

/**
 * Created by lin on 2017/10/26.
 */

public class BullListDialog extends Dialog {

    Context mcontext;
    ListView listviewJ, listviewM, listviewG;
    BullJxsAdapter adapter1;
    BullMendAdapter adapter2;
    BullGzlxAdapter adapter3;
    ChangeListener listener;

    public interface ChangeListener {
        public void changeJxs(String names, String jxsId);

        public void changeMd(String names,String id);

        public void changeGzlx(String names);
    }


    public BullListDialog(@NonNull Context context, @StyleRes int themeResId, ChangeListener listener) {
        super(context, themeResId);
        mcontext = context;
        this.listener = listener;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_bull_list_change);
        setCanceledOnTouchOutside(true);
        adapter1 = new BullJxsAdapter(mcontext);
        adapter2 = new BullMendAdapter(mcontext);
        adapter3 = new BullGzlxAdapter(mcontext);
        listviewJ = (ListView) findViewById(R.id.bull_list_changeJXS);
        listviewJ.setAdapter(adapter1);
        listviewJ.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                listener.changeJxs(adapter1.getItem(position).name , adapter1.getItem(position).id);
                dismiss();
            }
        });
        listviewM = (ListView) findViewById(R.id.bull_list_changeMD);
        listviewM.setAdapter(adapter2);
        listviewM.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                listener.changeMd(adapter2.getItem(position).name, adapter2.getItem(position).id);
                dismiss();
            }
        });
        listviewG = (ListView) findViewById(R.id.bull_list_changeGZ);
        listviewG.setAdapter(adapter3);
        listviewG.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                listener.changeGzlx(adapter3.getItem(position).codevalue);
                dismiss();
            }
        });

    }

    public void setDataJXS(List<BullJxsNewJob> listJxs) {
        listviewM.setVisibility(View.GONE);
        listviewG.setVisibility(View.GONE);
        listviewJ.setVisibility(View.VISIBLE);
        adapter1.clear();
        adapter1.addData(listJxs);
    }

    public void setDataMD(List<BullJxsNewJob> listJxs) {
        listviewJ.setVisibility(View.GONE);
        listviewG.setVisibility(View.GONE);
        listviewM.setVisibility(View.VISIBLE);
        adapter2.clear();
        adapter2.addData(listJxs);
    }

    public void setDataGZJL(List<BullGzlxEntity> listJxs) {
        listviewM.setVisibility(View.GONE);
        listviewJ.setVisibility(View.GONE);
        listviewG.setVisibility(View.VISIBLE);
        adapter3.clear();
        adapter3.addData(listJxs);
    }
}
